/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.expert.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.service.BaseService;
import com.chlitina.store.modules.expert.dao.SolutionFaceAndProductDao;
import com.chlitina.store.modules.expert.dao.SolutionFaceDao;
import com.chlitina.store.modules.expert.entity.SolutionFaceAndProduct;

/**
 * 面部护理方案与产品关系Service
 * @author lvbo
 * @version 2013-06-08
 */
@Component
@Transactional(readOnly = true)
public class SolutionFaceAndProductService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(SolutionFaceAndProductService.class);
	
	@Autowired
	private SolutionFaceAndProductDao solutionFaceAndProductDao;
	@Autowired
	private SolutionFaceDao solutionFaceDao;
	
	public SolutionFaceAndProduct getOneByPK(Long sid,Long pid) {
		return solutionFaceAndProductDao.findByPKId(sid, pid);
	}
	
	public List<SolutionFaceAndProduct> getBySolutionFaceId(Long sid) {
		return solutionFaceAndProductDao.findBySolutionId(sid);
	}
	
	public Page<SolutionFaceAndProduct> find(Page<SolutionFaceAndProduct> page, SolutionFaceAndProduct solutionFaceAndProduct, Long solutionId) {
		DetachedCriteria dc = solutionFaceAndProductDao.createDetachedCriteria();
		if (solutionId != null) {
			dc.add(Restrictions.eq("solutionFace.id", solutionId));
		}
		dc.addOrder(Order.asc("product.id"));
		return solutionFaceAndProductDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(SolutionFaceAndProduct solutionFaceAndProduct) {
		solutionFaceAndProductDao.save(solutionFaceAndProduct);
		solutionFaceDao.refresh(solutionFaceAndProduct.getSolutionFace());
	}
	
	@Transactional(readOnly = false)
	public void delete(SolutionFaceAndProduct solutionFaceAndProduct) {
		solutionFaceAndProductDao.delete(solutionFaceAndProduct);
	}
	
}
